<?php


namespace App\Request;

use Hyperf\Contract\ValidatorInterface;
use Hyperf\Validation\Contract\ValidatorFactoryInterface as ValidationFactory;
use Hyperf\Validation\Request\FormRequest;

class BaseRequest extends FormRequest
{
    protected $validationData;

    public function validate($data)
    {
        var_dump($data);
        $this->validationData = $data;
        var_dump($this->validationData);
        $container = \Hyperf\Utils\ApplicationContext::getContainer();  // 获取容器
        $this->setContainer($container);
        return $this->getValidatorInstance();
    }


    protected function createDefaultValidator(ValidationFactory $factory): ValidatorInterface
    {

        return $factory->make(
            $this->validationData,
            call_user_func_array([$this, 'rules'], []),
            $this->messages(),
            $this->attributes()
        );
    }

}
